package com.qidian.mes.produce.service.impl;

import com.alibaba.excel.EasyExcel;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qidian.common.pojo.MESResult;
import com.qidian.common.util.JSONTools;
import com.qidian.mes.pojo.Operate;
import com.qidian.mes.pojo.Process;
import com.qidian.mes.produce.mapper.OperateMapper;
import com.qidian.mes.produce.service.OperateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;
import java.util.List;

/**
 * @Author 陈俊成
 * @Company ccc
 * @Description
 * @Time 2024/10/17 16:51
 */
@Service
public class OperateServiceImpl implements OperateService {
    @Autowired
    OperateMapper operateMapper;
    @Override
    public MESResult queryAllByRelId(int relId,int page,int limit) {
        PageHelper.startPage(page,limit);
        List<Operate> operates = operateMapper.queryByRelId(relId);

        PageInfo<Operate> operatePageInfo = new PageInfo<>(operates);
        return MESResult.success(operatePageInfo);
    }

    @Override
    public MESResult addOperate(Operate operate) {
        if (operateMapper.addOperate(operate)==1){
            return MESResult.success();
        }
        return MESResult.error();
    }

    @Override
    public MESResult queryOneByRel(int operateRelId) {
        if (operateMapper.queryByOperateRelId(operateRelId)!=null){
            return MESResult.success(operateMapper.queryByOperateRelId(operateRelId));
        }
        return MESResult.error();
    }

    @Override
    public MESResult modifyOperate(Operate operate) {
        if (operateMapper.update(operate)==1){
            return MESResult.success();
        }
        return MESResult.error();
    }

    @Override
    public MESResult deleteOperate(int operateRelId) {
        if (operateMapper.updateStatus(operateRelId)==1){
            return MESResult.success();
        }
        return MESResult.error();
    }

    @Override
    public MESResult deleteChoose(List<Operate> operates) {
        for (int i = 0; i < operates.size(); i++) {
            if (operateMapper.updateStatus(Integer.parseInt(operates.get(i).getOperateRelId()))!=1){
                return MESResult.error();
            }

        }
        return MESResult.success();
    }

}
